<?php

class Core_Pack 
{
	/**
	 * suma pól
	 * @var int
	 */
	public $area = 0;
	
	/**
	 * waga
	 * @var int
	 */
	public $weight = 0;
	
	/**
	 * pusta przestrzeń jaka musi zostać w pudełkach w %
	 * @var int
	 */
	public $empty = 20;
	
	/**
	 * wynik
	 * 
	 * @var int
	 */
	public $result = 0;
	
	/**
	 * area - pole powierzchni w milimetrach
	 * weight - dopuszczalana waga dla pudełka w gramach
	 * price - cena za pudełko
	 * price_for_overweight - cena za przekroczenie wagi
	 * overweight - co ile gram naliczać stawkę za przekroczenie
	 * 
	 * @var array
	 */
	public $items = array(
		array(
			'area' => 30000,
			'weight' => 1000,
			'price' => 10,
			'price_for_overweight' => 1,
			'overweight' => 100
		),
		array(
			'area' => 60000,
			'weight' => 2000,
			'price' => 20,
			'price_for_overweight' => 1,
			'overweight' => 100
		),
		array(
			'area' => 90000,
			'weight' => 4000,
			'price' => 30,
			'price_for_overweight' => 1,
			'overweight' => 100
		),
		array(
			'area' => 130000,
			'weight' => 6000,
			'price' => 40,
			'price_for_overweight' => 1,
			'overweight' => 100
		)
	);
	
	/**
	 * kostruktor
	 * 
	 * @param int $area
	 * @param int $weight
	 * @return void
	 */
	public function __construct( $area, $weight ) {
		$this->area = $area;
		$this->weight = $weight;
	}
	
	/**
	 * funkcja oblicza jaki i ile pudełek potrzeba do spakowania
	 * 
	 * @return array
	 */
	public function calc() {
		$last;

		foreach( $this->items as $value ) {

			if( $value['area'] > $this->area ) {
				$this->area = 0;
				$this->result = $this->result + $value['price'];
				return $this->result;
			}

			$last = $value;
		}

		if( $this->area > 0 ) {
			$this->area = $this->area - $last['area'];
			$this->result = $this->result + $last['price'];
			$this->calc();
		}

	}
}